<!--
 * @Description: 第三方授权页面
 * @Version: 1.0
 * @Author: Yuanjy
 * @Date: 2020-03-12 15:27:54
 * @LastEditors: Yuanjy
 * @LastEditTime: 2020-05-08 17:07:08
 -->
<template>
  <div>
    <div v-if="auth_code" class="el-loading-mask">
      <div class="el-loading-spinner" style="top:30%">
        <svg viewBox="25 25 50 50" class="circular" style="width:62px;height:62px;">
          <circle cx="50" cy="50" r="20" fill="none" class="path" />
        </svg>
        <p class="el-loading-text" style="margin:20px 0; font-size:16px;">授权中，请稍候......</p>
      </div>
    </div>
    <div v-else>
      <div class="el-loading-spinner" style="top:30%">
        <svg viewBox="25 25 50 50" class="circular" style="width:62px;height:62px;">
          <circle cx="50" cy="50" r="20" fill="none" class="path" />
        </svg>
        <p class="el-loading-text" style="margin:20px 0; font-size:16px;">授权码生成中，请稍候......</p>
      </div>
    </div>
  </div>
</template>

<script>
import { getQueryString } from '@/utils'

export default {
  data() {
    return {
      auth_code: getQueryString('auth_code')
    }
  },
  created() {
    if (this.auth_code) {
      this.authEnterprise()
    } else {
      this.preAuthEnterprise()
    }
  },
  methods: {
    authEnterprise() {
      this.$api.permission.auth
        .authEnterprise({
          data: { auth_code: this.auth_code }
        })
        .then(res => {
          window.location.href = res.data.login_url
        }).catch(err => {
          console.log(err)
        })
    },
    preAuthEnterprise() {
      this.$api.permission.auth
        .preAuthUrl()
        .then(res => {
          window.open(res.data.pre_auth_url)
        }).catch(err => {
          console.log(err)
        })
    }
  }
}
</script>
